<template>
  <div class="login-container">
    <div class="login-background">
      <div class="book-pattern"></div>
      <div class="gradient-overlay"></div>
    </div>

    <div class="login-card">
      <div class="login-header">
        <h2>图书推荐系统</h2>
        <p>管理员后台登录</p>
      </div>

      <el-form ref="form" :model="form" class="login-form">
        <el-form-item>
          <el-input v-model="form.account" placeholder="请输入管理员账号" prefix-icon="el-icon-user"
            class="login-input"></el-input>
        </el-form-item>

        <el-form-item>
          <el-input type="password" v-model="form.password" placeholder="请输入密码" prefix-icon="el-icon-lock"
            class="login-input" show-password></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="login" class="login-btn" :loading="loading">
            {{ loading ? '登录中...' : '登 录' }}
          </el-button>
        </el-form-item>
      </el-form>

      <div class="login-footer">
        <p>© 2025 图书推荐系统 | 管理员后台</p>
      </div>
    </div>

    <div class="floating-books">
      <div class="book book-1"></div>
      <div class="book book-2"></div>
      <div class="book book-3"></div>
      <div class="book book-4"></div>
      <div class="book book-5"></div>
      <div class="book book-6"></div>
      <div class="book book-7"></div>
      <div class="book book-8"></div>
      <div class="book book-9"></div>
      <div class="book book-10"></div>
      <div class="book book-11"></div>
      <div class="book book-12"></div>
      <div class="book book-13"></div>
      <div class="book book-14"></div>
      <div class="book book-15"></div>
      <div class="book book-16"></div>
      <div class="book book-17"></div>
      <div class="book book-18"></div>
      <div class="book book-19"></div>
      <div class="book book-20"></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        account: '',
        password: ''
      },
      loading: false
    }
  },
  methods: {
    login() {
      if (!this.form.account) {
        this.$message.error('请输入管理员账号');
        return;
      }
      if (!this.form.password) {
        this.$message.error('请输入密码');
        return;
      }

      this.loading = true;

      this.$axios.post('/api/admin/login', {
        account: this.form.account,
        password: this.form.password
      })
        .then(res => {
          if (res.data.code == '001') {
            localStorage.setItem('adminUserInfo', res.data.data);
            this.$message.success('登录成功');
            this.$router.push('/');
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch(() => {
          this.$message.error('登录失败，请稍后重试');
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
}
</script>

<style scoped>
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
}

.login-background {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.book-pattern {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect fill="rgba(255,255,255,0.05)" width="50" height="50" x="0" y="0"></rect><rect fill="rgba(255,255,255,0.05)" width="50" height="50" x="50" y="50"></rect></svg>');
  background-size: 20px 20px;
  opacity: 0.3;
}

.gradient-overlay {
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 75% 50%, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 50%);
}

.login-card {
  position: relative;
  width: 380px;
  padding: 40px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 15px 35px rgba(50, 50, 93, 0.1), 0 5px 15px rgba(0, 0, 0, 0.07);
  z-index: 10;
  transform: translateY(0);
  transition: all 0.3s ease;
  animation: fadeInUp 0.6s ease;
}

.login-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 18px 40px rgba(50, 50, 93, 0.15), 0 8px 20px rgba(0, 0, 0, 0.1);
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-header h2 {
  color: #2d3748;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-header p {
  color: #718096;
  font-size: 14px;
}

.login-form {
  margin-top: 20px;
}

.login-input {
  margin-bottom: 20px;
}

.login-input /deep/ .el-input__inner {
  height: 48px;
  line-height: 48px;
  border-radius: 8px;
  padding-left: 40px;
  border: 1px solid #e2e8f0;
  transition: all 0.3s;
}

.login-input /deep/ .el-input__inner:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.login-input /deep/ .el-input__prefix {
  left: 10px;
  color: #a0aec0;
}

.login-btn {
  width: 100%;
  height: 48px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 1px;
  background: linear-gradient(to right, #667eea, #764ba2);
  border: none;
  transition: all 0.3s;
}

.login-btn:hover {
  background: linear-gradient(to right, #5a6fd1, #6a4298);
  transform: translateY(-2px);
  box-shadow: 0 7px 14px rgba(102, 126, 234, 0.3);
}

.login-footer {
  margin-top: 30px;
  text-align: center;
  font-size: 12px;
  color: #a0aec0;
}

.floating-books {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

.book {
  position: absolute;
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.7;
  animation: float 6s ease-in-out infinite;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

/* 书本1-5: 不同大小和颜色的基础书本 */
.book-1 {
  width: 80px;
  height: 100px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFFFFF"><path d="M3 18h12v-2H3v2zM3 6v2h18V6H3zm0 7h18v-2H3v2z"/></svg>');
  top: 15%;
  left: 8%;
  animation-delay: 0s;
}

.book-2 {
  width: 60px;
  height: 80px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFD700"><path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/></svg>');
  top: 65%;
  left: 82%;
  animation-delay: 1s;
}

.book-3 {
  width: 70px;
  height: 90px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF6B6B"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 30%;
  left: 72%;
  animation-delay: 2s;
}

.book-4 {
  width: 65px;
  height: 85px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2348dbfb"><path d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>');
  top: 75%;
  left: 15%;
  animation-delay: 0.5s;
}

.book-5 {
  width: 90px;
  height: 110px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2398FB98"><path d="M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM8 20H4v-4h4v4zm0-6H4v-4h4v4zm0-6H4V4h4v4zm6 12h-4v-4h4v4zm0-6h-4v-4h4v4zm0-6h-4V4h4v4zm6 12h-4v-4h4v4zm0-6h-4v-4h4v4zm0-6h-4V4h4v4z"/></svg>');
  top: 20%;
  left: 85%;
  animation-delay: 1.5s;
}

/* 书本6-10: 不同形状的书本 */
.book-6 {
  width: 55px;
  height: 75px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFA500"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 40%;
  left: 10%;
  animation-delay: 2.5s;
}

.book-7 {
  width: 75px;
  height: 95px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23BA55D3"><path d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>');
  top: 55%;
  left: 75%;
  animation-delay: 0.8s;
}

.book-8 {
  width: 60px;
  height: 80px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2300CED1"><path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/></svg>');
  top: 25%;
  left: 25%;
  animation-delay: 1.8s;
}

.book-9 {
  width: 85px;
  height: 105px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF6347"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 70%;
  left: 25%;
  animation-delay: 0.3s;
}

.book-10 {
  width: 50px;
  height: 70px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2320B2AA"><path d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>');
  top: 45%;
  left: 85%;
  animation-delay: 2.2s;
}

/* 书本11-15: 更多变化 */
.book-11 {
  width: 70px;
  height: 90px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF8C00"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 15%;
  left: 60%;
  animation-delay: 1.2s;
}

.book-12 {
  width: 65px;
  height: 85px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239370DB"><path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/></svg>');
  top: 80%;
  left: 70%;
  animation-delay: 0.7s;
}

.book-13 {
  width: 55px;
  height: 75px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF69B4"><path d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>');
  top: 35%;
  left: 45%;
  animation-delay: 2.8s;
}

.book-14 {
  width: 80px;
  height: 100px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2300BFFF"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 60%;
  left: 10%;
  animation-delay: 1.5s;
}

.book-15 {
  width: 60px;
  height: 80px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%233CB371"><path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/></svg>');
  top: 25%;
  left: 40%;
  animation-delay: 0.9s;
}

/* 书本16-20: 最后一批书本 */
.book-16 {
  width: 75px;
  height: 95px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FF4500"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 50%;
  left: 60%;
  animation-delay: 2.5s;
}

.book-17 {
  width: 65px;
  height: 85px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23DA70D6"><path d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>');
  top: 75%;
  left: 50%;
  animation-delay: 1.1s;
}

.book-18 {
  width: 70px;
  height: 90px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234B0082"><path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"/></svg>');
  top: 40%;
  left: 20%;
  animation-delay: 2.3s;
}

.book-19 {
  width: 55px;
  height: 75px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23008080"><path d="M18 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM6 4h5v8l-2.5-1.5L6 12V4z"/></svg>');
  top: 65%;
  left: 85%;
  animation-delay: 0.6s;
}

.book-20 {
  width: 85px;
  height: 105px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23C71585"><path d="M3 6h18v2H3V6zm0 5h18v2H3v-2zm0 5h18v2H3v-2z"/></svg>');
  top: 20%;
  left: 30%;
  animation-delay: 1.9s;
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(5deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* 响应式调整 - 在小屏幕上减少书本数量 */
@media (max-width: 768px) {
  .book-6, .book-7, .book-8, .book-9, .book-10,
  .book-11, .book-12, .book-13, .book-14, .book-15,
  .book-16, .book-17, .book-18, .book-19, .book-20 {
    display: none;
  }
}
</style>